package com.study;

import com.study.event.MyEvent;
import com.study.listener.MyListener1;
import com.study.utils.ApplicationContextUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;


@SpringBootApplication
@EnableAsync
public class App {

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(App.class);
        //要先装载事件
        springApplication.addListeners(new MyListener1());

        ConfigurableApplicationContext context = springApplication.run(args);

        //发布事件
        context.publishEvent(new MyEvent("测试事件."));
        //ApplicationContextUtil.getApplicationContext().publishEvent(new MyEvent("测试事件."));

    }
}

//@SpringBootApplication
//public class App {
//    public static void main(String[] args) {
//        ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
//        //装载事件
//        context.addApplicationListener(new MyListener1());
//        //发布事件
//        context.publishEvent(new MyEvent("测试事件."));
//    }
//}

/**
 将一个数组转换为 List
 String[] myArray = { "Apple", "Banana", "Orange" }；
 List<String> myList = Arrays.asList(myArray);

 List<String> myList = Arrays.asList("Apple", "Orange");
 */